#include <ui_fscreenw.h>
#include <QLabel>
#include <QDialog>
#include <QSignalMapper>
#include <QObject>
#include <QImage>
#include <tile.h>
#include <QPoint>
#include <QTabWidget>


class CLabelBtn;

class CScreenW : public QDialog, public Ui_FScreenW
{
	Q_OBJECT
	
public:
	CScreenW();

	void Initialize();

	void NewScreen();
	bool LoadScreen( QString fileName );
	bool SaveScreen( QString fileName );
	bool ExportScreen( QString fileName );

	void NewTiles();
	bool LoadTiles( QString fileName );
	bool SaveTiles( QString fileName );
	bool ExportTiles( QString fileName );

	void Close();
	
protected:
	void closeEvent( QCloseEvent *pEvent );
	
private:
//	static const uint COLORS_TABLE[16];

	QTabWidget *m_pTabBank;
	QFrame *m_pFrmBank[3];
	CLabelBtn *m_pLblBank[3];
	CLabelBtn *m_pLblPalette;
	CLabelBtn *m_pLblTile;
	CLabelBtn *m_pLblColors;
	CLabelBtn *m_pLblScreen;
	CTile m_TilesBank[256][3];
	CTile m_TileDesign;
	int m_Screen[256*3];
	QPoint m_SelColor;
	QPoint m_SelTile;
	bool m_Close;
	QImage m_BankImages[3];
	
//	void SetPixelRect( QImage *pImage, int x, int y, uint color, int w, int h );
//	void SetBorderImage( QImage *pImage, int x, int y, int w, int h, int color );
	void CopyToTileDesign( int index, int bank );
	void SetTileDesign();
	void UpdateBank( int tile, int bank, bool updateBank = true );
	void UpdateScreen();
	void InitBanks();
	
	void PaintTile( QImage *pImage, CTile &tile, int posX, int posY, int dotSize );
	void PaintGrid( QImage *pImage, int gridWidth, int gridHeight );
	
	void OnBankClick( int x, int y, int bank );

public slots:
	void OnBank0Click( int x, int y);
	void OnBank1Click( int x, int y);
	void OnBank2Click( int x, int y);
	void OnPaletteClick( int x, int y );
	void OnColorsClick( int x, int y );
	void OnTileClickLeft( int x, int y );
	void OnTileClickRight( int x, int y );
	void OnFromBank();
	void OnToBank();
	void OnScreenClick( int x, int y );
	void OnRadBack();
	void OnRadFore();
	void OnBankChanged( int index );
};
